layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    $(".loginBody .seraph").click(function(){
        layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧",{
            time:5000
        });
    })

    //登录按钮
    form.on("submit(login)",function(data){
        console.log(data);
        var that = $(this);
        that.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
        setTimeout(function(){
             $.ajax({
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: loginUrl,
                data: $('#form').serialize(),
                success: function (res) {
                    if (res.code == 1) {
                        that.text("登录").attr("disabled",false).removeClass("layui-disabled");
                        layer.msg(res.message);
                    }
                    if (res.code == 0) {
                        top.location.href = indexUrl;
                    }
                },
                error: function () {
                    console.log("异常");
                }
            });
        },500);
        return false;
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })

    //验证码刷新
    $(".vcode").click(function(e){
        var url = vcodeUrl + "?id="+Math.ceil(Math.random()*100000);
        $(".vcode").attr("src",url);
    });
})
